package org.epsi.blokus.state;

import de.matthiasmann.twl.Button;
import org.epsi.blokus.TWL_Slick_Binding.BasicTWLGameState;
import org.epsi.blokus.entity.dialog.LoginDialog;
import org.epsi.blokus.tools.I18n;
import org.epsi.blokus.tools.IConstantes;
import org.epsi.blokus.tools.Log;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

/**
 *
 * @author julien.lafont
 */
public class InitState extends BasicTWLGameState implements IConstantes {


    private GameContainer container;
    private StateBasedGame game;

    // GUI
    private LoginDialog dialogLogin = new LoginDialog();
    private Button btnQuitter;
    
    @Override
    public int getID() {
        return ID_STATE_INIT;
    }

    
    public void init(GameContainer container, StateBasedGame game) throws SlickException {

        Log.out("InitState : init");
                
        this.container = container;
        this.game = game;

        dialogLogin.init(container, game);

    }

    public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
        g.setAntiAlias(true);
        dialogLogin.render(container, game, g);
    }



    public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
        dialogLogin.update(container, game, delta);
    }


    // ---------------------------------- PARTIE GUI -------------------------------- //


    @Override
    protected void createRootPane() {
        super.createRootPane();
        rootPane.setTheme("initstate");
        rootPane.add(dialogLogin);

        btnQuitter = new Button(I18n.get("Quitter"));
        btnQuitter.addCallback(callBackBtnQuitter);
        rootPane.add(btnQuitter);
    }

   @Override
    protected void layoutRootPane() {
        super.layoutRootPane();
        dialogLogin.updateRequested();

        btnQuitter.adjustSize();
        btnQuitter.setPosition(850, 700);
    }



   // ---------------------------------- Callbacks  -------------------------------- //
   
   Runnable callBackBtnQuitter = new Runnable() {
        public void run() {
            System.exit(0);
        }
    };

}
